<?php
/**
 * 示例model（标注表的作用）
 * panglishan
 * 2020.08.13
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class WinLog extends Model{

    protected $table = 'ln_win_log';     //数据库内完整表名

    protected $primaryKey = 'id';    //主键名

    protected $fillable = [
        'id',      //主键ID
        'user_id',         //主播uid
        'gift_id',      //礼物id
        'add_time'     //创建时间
    ];
    public $timestamps = false;
    public function setUnionAllTable()
    {
        $sql =<<<'EOT'
            SELECT * FROM ln_win_log_1
            UNION ALL
            SELECT * FROM ln_win_log_2
            UNION ALL
            SELECT * FROM ln_win_log_3
            UNION ALL
            SELECT * FROM ln_win_log_4
            UNION ALL
            SELECT * FROM ln_win_log_5
            UNION ALL
            SELECT * FROM ln_win_log_6
            UNION ALL
            SELECT * FROM ln_win_log_7
            UNION ALL
            SELECT * FROM ln_win_log_8
            UNION ALL
            SELECT * FROM ln_win_log_9
            UNION ALL
            SELECT * FROM ln_win_log_10
EOT;
        return $this->setTable(DB::raw("({$sql}) AS users_all"));
    }

    public  function  gift(){
        return $this->hasOne('App\Models\MainDB\Gift','id','gift_id');
    }
    public  function  user_data(){
        return $this->hasOne('App\Models\MainDB\UserData','user_id','user_id');
    }

}